package patrol.mobile.com.mobilepatrol.activity.toll;

import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.listener.OnRecyclerViewItemClickListener;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import okhttp3.Call;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.CommonListActivity;
import patrol.mobile.com.mobilepatrol.adapter.EvaluationDetailAdapter;
import patrol.mobile.com.mobilepatrol.api.Urls;
import patrol.mobile.com.mobilepatrol.bean.EvaluationDetailBean;
import patrol.mobile.com.mobilepatrol.bean.EvaluationDetailBean2;
import patrol.mobile.com.mobilepatrol.bean.JobEvaluationInformationBean;
import patrol.mobile.com.mobilepatrol.manager.UserManager;
import patrol.mobile.com.mobilepatrol.utils.Constants;
import patrol.mobile.com.mobilepatrol.utils.GsonUtil;
import patrol.mobile.com.mobilepatrol.utils.SPUtils;
import patrol.mobile.com.mobilepatrol.utils.net.HttpCallBack;
import patrol.mobile.com.mobilepatrol.utils.net.HttpSender;

public class EvaluationDetailActivity extends CommonListActivity {

    private TextView mTv1;
    private TextView mTv2;
    private TextView mTv3;
    private JobEvaluationInformationBean bean;

    @Override
    protected BaseQuickAdapter initAdapter() {
        return new EvaluationDetailAdapter(this);
    }

    @Override
    protected String initTitleName() {
        return "考核明细";
    }

    @Override
    public void initView() {
        super.initView();
        View inflate = LayoutInflater.from(this).inflate(R.layout.activity_evaluation_detail_top, null);
        flContent.addView(inflate);
        mTv1 = inflate.findViewById(R.id.tv1);
        mTv2 = inflate.findViewById(R.id.tv2);
        mTv3 = inflate.findViewById(R.id.tv3);

        bean = (JobEvaluationInformationBean) getIntent().getSerializableExtra("list");
        Log.i("123", "initView: "+bean.getCheckName());
        mTv1.setText("被考核人：" + bean.getCheckName());
        mTv2.setText("考核人：" + bean.getAssessor());
        mTv3.setText("总扣分：" + bean.getDeductScore());
    }

    @Override
    public void configAdapter() {
        super.configAdapter();
        mAdapter.updateItems(bean.getOrgPostItemList());
//        requestData();
    }

    private void requestData(){
        HttpSender sender = new HttpSender(this,baseUrl,Urls.GET_ORG_POST_TEMPLATE_LIST);
        HashMap<String,String> map = new HashMap<>();
        map.put("post",bean.getAssessmentPost());
        map.put("department",bean.getOrgName());
        sender.requestPost(map, new HttpCallBack(sender) {
            @Override
            public void onError(String code, Call call, Exception e) {

            }

            @Override
            public void onResponse(String code, String response) {
                List<EvaluationDetailBean2> evaluationDetailBean2s = GsonUtil.jsonToList(response, EvaluationDetailBean2.class);

            }
        });
    }

    @Override
    public void setListener() {
        super.setListener();
        mAdapter.setOnItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                if (bean == null) return;
                Intent intent = new Intent(EvaluationDetailActivity.this, EvaluationContentActivity.class);
                intent.putExtra("list", bean);
                intent.putExtra("position", position);
                startActivity(intent);
            }
        });
    }
}
